package com.sanjiahantang.youjiarole.module.store.preseneters;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.sanjiahantang.uilibrary.adapter.listview.BaseAdapterHelper;
import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpPresenter;
import com.sanjiahantang.youjiarole.base.CallBack;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.module.store.beans.StoreBean;
import com.sanjiahantang.youjiarole.module.store.models.IStoreModel;
import com.sanjiahantang.youjiarole.module.store.models.impl.StoreModel;
import com.sanjiahantang.youjiarole.module.store.views.StoreView;
import com.sanjiahantang.youjiarole.module.store.views.impl.StoreOnMapActivity;
import com.squareup.picasso.Picasso;

/**
 * Created by zy on 2017/9/20.
 */

public class StorePresenter extends BaseMvpPresenter<StoreView> implements CallBack<StoreBean> {
    private StoreView.OnLoadListener onLoadListener;
    private IStoreModel storeModel;
    private QuickAdapter<StoreBean.Data> storeAdapter;
    public StorePresenter(){
        storeModel = new StoreModel();
    }

    public void loadData(Context context, StoreView.OnLoadListener onLoadListener) {
        this.onLoadListener = onLoadListener;
        mView.showProgress();
        storeModel.loadStoreList(context,this);
    }

    @Override
    public void onSuccess(StoreBean response, Context context, Object tag) {
        mView.hideProgress();
        storeAdapter = new QuickAdapter<StoreBean.Data>(context, R.layout.item_store,response.getData()) {
            @Override
            protected void convert(BaseAdapterHelper helper, StoreBean.Data item) {
                /*helper.setText(R.id.nearby_shop_name,item.getTitle());
                helper.setText(R.id.nearby_address,item.getAddress());
                helper.setText(R.id.nearby_distance,item.getDistance());
                Picasso.with(context).load(ConfigValue.IMG_IP + item.getImg()).into((ImageView) helper.getView(R.id.nearby_shop_img));
                helper.setOnClickListener(R.id.llDistance, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        goPageSimply(context,StoreOnMapActivity.class);
                    }
                });*/
            }
        };

        onLoadListener.initListView(storeAdapter);
    }

    @Override
    public void onFailure(String message) {
        mView.hideProgress();
    }
}
